/*
2019.9.19
*/
#include<iostream>
#include<string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
class Solution {
public:
    string addBinary(string a, string b) 
	{
		string str="",sum;
        int carry=0,int_a,int_b;
        int i=a.length()-1,j=b.length()-1;
        
        for(;i>=0&&j>=0;i--,j--)
        {
        	int_a=a[i]-'0';
        	int_b=b[j]-'0';
        
        	str+=std::to_string( (int_a+int_b+carry)%2 );
        	carry=(carry+int_a+int_b)/2;

        	
		}
		while(i>=0)
		{
			int_a=a[i]-'0';
			sum=std::to_string( (int_a+int_b+carry)%2 );
			str+=std::to_string( (int_a+carry)%2 );
			
//			cout<<"a["<<i<<"]="<<a[i]<<'\t'<<"b["<<j<<"]="<<b[j]<<'\t'<<carry<<'\t'<<sum<<endl;
			
			carry=(carry+int_a)/2;
//			cout<<"carry="<<carry<<endl; 
			i--;
		}
		
		while(j>=0)
		{
			int_b=b[j]-'0';
			sum=std::to_string( (int_a+int_b+carry)%2 );
			str+=std::to_string( (int_b+carry)%2 );
			
//			cout<<"a["<<i<<"]="<<a[i]<<'\t'<<"b["<<j<<"]="<<b[j]<<'\t'<<carry<<'\t'<<sum<<endl;
			
			carry=(carry+int_b)/2;
//			cout<<"carry="<<carry<<endl; 
			j--;
		}
		
		if(carry)
		{
			str+=std::to_string(carry);
		}
		
		string str_res="";
		for(int i=str.length()-1;i>=0;i--)
		{
			str_res+=str[i];
		}
		return str_res;
    }
};
int main()
{
	Solution solution;
	string a="1",b="111";
	cout<<solution.addBinary(a,b)<<endl; ;
	return 0;
}
